﻿namespace Bookify.Web.Services.Share
{
    public static class DateServcie
    {
        public static (DateOnly StartDate, DateOnly EndDate) ParseDateRange(string dateRangeText)
        {
            var startDate = default(DateOnly);
            var endDate = default(DateOnly);

            if (!string.IsNullOrEmpty(dateRangeText))
            {
                var parts = dateRangeText.Split('~');
                if (parts.Length == 2)
                {
                    if (DateOnly.TryParse(parts[0].Trim(), out DateOnly start))
                    {
                        startDate = start;
                    }
                    if (DateOnly.TryParse(parts[1].Trim(), out DateOnly end))
                    {
                        endDate = end;
                    }
                }
            }

            return (startDate, endDate);
        }

        public static string FormatDateRange(DateOnly startDate, DateOnly endDate)
        {
            return $"{startDate:yyyy-MM-dd} ~ {endDate:yyyy-MM-dd}";
        }

        public static Bookify.Web.Services.Base.DateOnly FromSystemDateOnly(System.DateOnly systemDate)
        {
            return new Bookify.Web.Services.Base.DateOnly
            {
                Year = systemDate.Year,
                Month = systemDate.Month,
                Day = systemDate.Day
            };
        }
       
    }
}
